#include <bits/stdc++.h>
using namespace std;
int T;
int n,m,L,V;
int p;
int ans,k;
struct node
{
    int d;
    int v;
};
node a[100005];
bool cmp(node x,node y)
{
    return x.d>y.d;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--)
    {
        ans=0,k=0;
        scanf("%d%d%d%d",&n,&m,&L,&V);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&a[i].d,&a[i].v,&a);
            if(a[i].v>V) ans++;
        }
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=m;i++) scanf("%d",&p);
        for(int i=1;a[i].d>p;i++)
            if(a[i].v>V) k++;
        ans-=k;
        printf("%d %d\n",ans,ans?(m-1):m);
    }
    return 0;
}
